/*
 * author      : 吴中勤 
 * date        : 2018/9/26
 * description : 物料 - 行项目类别 对应关系表
 */

package com.deepexi.adapter.converter.sap.sapdict;

import com.deepexi.adapter.facade.moby.request.MobyEventBody;
import com.deepexi.adapter.facade.moby.request.MobyOrderLine;

import java.util.Date;

public class Material2ItCatFactory {

    /** 录入一个没有对应关系的物料, 便于后续补全 */
    public static Material2ItCat lostRecordOfMaterial2Itcat(MobyEventBody body, MobyOrderLine mobyLine) {
        String desc = new StringBuilder()
                .append("itemName:").append(mobyLine.getItemName())
                .append(", propNames:").append(mobyLine.getPropNames())
                .append(", propValues:").append(mobyLine.getPropValues())
                .toString();

        return newMaterial2CatNotConfirmed(
                body.getMobyTradeOrder().getOrderTypeCode(),
                body.getMobyTradeOrder().getOrderType(),
                mobyLine.getProductType(),
                mobyLine.getMaterialCode(),
                desc
        );
    }

    private static Material2ItCat newMaterial2CatNotConfirmed(
            String orderSenseCode,  // 必须
            String orderSenseName,  // 必须
            String lineSenseName,   // 必须
            String materialCode,    // 必须
            String desc             // 可选
    ) {
        /* 插入到 数据库, 待补全 */
        Material2ItCat lostMapInfo = new Material2ItCat();
        lostMapInfo.setOrderSenseCode(orderSenseCode);
        lostMapInfo.setOrderSenseName(orderSenseName);
        lostMapInfo.setLineSenseName(lineSenseName);
        lostMapInfo.setMaterialCode(materialCode);
        lostMapInfo.setMaterialDesc("TODO");
        lostMapInfo.setSapItcatDesc("TODO");
        /* 此项记录不可用状态 */
        lostMapInfo.setActive(0);
        lostMapInfo.setField01(desc);
         /* 缺失情况时补充录入 */
        lostMapInfo.setField11(1);
        lostMapInfo.setCreatedAt(new Date());

        return lostMapInfo;
    }

}